package com.freedom.admin.domain.service.impl;

import com.freedom.admin.domain.repository.SysUserRepository;
import com.freedom.admin.domain.service.UserService;
import com.freedom.admin.infrastructure.persistence.pojo.bo.UserBO;
import com.freedom.common.core.constant.SystemConstant;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final SysUserRepository sysUserRepository;

    private final PasswordEncoder passwordEncoder;

    @Override
    public Integer save(UserBO userBO) {
        String password = passwordEncoder.encode(SystemConstant.DEFAULT_USER_PASSWORD);
        userBO.setPassword(password);
        return sysUserRepository.save(userBO);
    }

    @Override
    public void modifyById(UserBO userBO) {
        sysUserRepository.modifyById(userBO);
    }

    @Override
    public void removeByIds(List<Integer> ids) {
        sysUserRepository.removeByIds(ids);
    }

    @Override
    public void modifyUser(UserBO userBO) {
        sysUserRepository.modifyUser(userBO);
    }
}
